Ext.ns('Wlanauth.message');
Wlanauth.message.ViewDetail = function(id){
	var iWidth=610;                          //弹出窗口的宽度;
    var iHeight=455;                         //弹出窗口的高度;
    //获得窗口的垂直位置
    var iTop = (window.screen.availHeight-30-iHeight)/2;       
    //获得窗口的水平位置
    var iLeft = (window.screen.availWidth-10-iWidth)/2;
    var cfg = 'innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no';
    
	window.open('message!viewDetailPage.action?entity.id='+id,'newwindow_message',cfg);
}

Wlanauth.message.GridPanel = Ext.extend(Wlanauth.BaseGridPanel,{
	title:'留言管理',
	storeUrl:'message!list.action',
	pageSize:10,
	constructor:function(cfg){
		Ext.apply(this,cfg);
		
		function renderMessage(value, p, record) {
			var content = record.get('content');
			if(content.length>500){
				content = content.replace(/<.+>/g,'');
			}
			
	        var html='用户 <font style="color:#666999">'+record.get('username')+'</font> 说:<br/>';
	        html+='<div style="height:50px;"><a href="javascript:void(0)" onclick="Wlanauth.message.ViewDetail(\''+record.get('id')+'\')">'+content+'</a></div>';
	        return html;
	    }
		function checkedRender(val){
			if(val){
				return '<font style="color:blue">是</font>';
			}
			return '<font style="color:red">否</font>';
		}
		this.store = new Ext.data.JsonStore({
			url:this.storeUrl,
			totalProperty:'data',
			root:'rows',
			fields:['id','username','email','title','content',
			        {name:'createTime',type:'date',dateFormat:'Y-m-d H:i:s'}]
			
		});
		var sm = new Ext.grid.CheckboxSelectionModel();
		var config = {
			loadMask:true,
			sm:sm,
			cm:new Ext.grid.ColumnModel({
				columns:[new Ext.grid.RowNumberer(),
				    {header:'留言',id:'content',renderer:renderMessage},
				    {header:'邮箱',dataIndex:'email',width:180},
				    {header:'留言时间',dataIndex:'createTime',width:150,renderer:Ext.util.Format.dateRenderer("Y-m-d H:m:s"),sortable:true},
				    {header:'是否审核',dataIndex:'checked',width:80,renderer:checkedRender,sortable:true}
			    ]}),
			autoExpandColumn:'content'
		};
		
		Wlanauth.message.GridPanel.superclass.constructor.call(this,config);
		this.on('rowdblclick',this.editObject,this);
		this.fireEvent('autoload');
		
	},
	
	deleteObject:function(){
		var grid = this;
		var rs = this.getSelectionModel().getSelections();
		if(rs.length<1){Ext.Msg.alert('提示','请至少选择一项');return;}
		var ids = '',_html='';
		for(var i=0;i<rs.length;i++){
			ids+=rs[i].get('id');
			if(i%5==0){
				_html+='<br/>';
			}
			_html+=rs[i].get('username');
			if(i<rs.length-1){
				ids+=',';
				_html+=' ; ';
			}
		}
		Ext.Msg.confirm('警告','<font style="color:red;font-weight:bold">您确定删除以下记录吗?  卡号:</font><br/>'+_html,function(btn){
			if(btn=='yes'){
				Ext.Msg.wait('删除...');
				Ext.Ajax.request({
					url:'user!batchDelete.action',
					params:{userIds:ids},
					success:function(response,opts){
						if(checkException(response)){
							Ext.Msg.alert('提示','删除成功');
							grid.getStore().reload();
						}
					}
				
				});
			} 
		});
		
	}
	
});

Ext.reg('wlanauth.message.gridpanel',Wlanauth.message.GridPanel);